<template>
	<view class="">
		<view class="word" v-show="$store.state.load">图片正在导入...,请勿退出App</view>
		<view class="all">
			实测得分:{{allscore}}
		</view>
		<view class="all">
			扣分合计:{{tolscore}}
		</view>
		<view class="all">
			扣分详细情况如下:
		</view>
		<table v-if="oneiswhich" v-for="(i,index) in allpoint" :key="allpoint.id" style="margin: 0 auto; border-collapse: collapse;" border="1">
			<tr>
				<td>{{i.point}}</td>
				<td v-show="$store.state.score > index ? false:true">仅参考</td>
				<td v-show="$store.state.score > index ? true:false">{{i.Imageall.length}} × {{score}} = {{i.Imageall.length*score>0.6?  (i.Imageall.length*score).toFixed(2) + dist1:(i.Imageall.length*score).toFixed(2)}}</td>
			</tr>
		</table>
		<table v-if="twoiswhich" v-for="(i,index) in allpoint" :key="allpoint.id" style="margin: 0 auto; border-collapse: collapse;" border="1">
			<tr>
				<td>{{i.point}}</td>
				<td v-show="$store.state.score > index ? false:true">仅参考</td>
				<td v-show="$store.state.score > index ? true:false">{{i.Imageall.length}} × {{score}} = {{i.Imageall.length*score>2? (i.Imageall.length*score).toFixed(2) + dist2:(i.Imageall.length*score).toFixed(2)}}</td>
				
			</tr>
		</table>
		<view v-if="oneiswhich" v-for="(i,index) in allpoint" :key="allpoint.id">
			<view class="">{{i.name}}</view>
			<br>
			<view class="length" v-show="$store.state.score > index ? false:true">仅参考</view>
			<view class="length" v-show="$store.state.score > index ? true:false">扣分值：{{i.Imageall.length}} × {{score}} = {{i.Imageall.length*score>0.6? (i.Imageall.length*score).toFixed(2) + dist1:(i.Imageall.length*score).toFixed(2)}}</view>
			<br>
			<view>扣分依据：{{i.point}}</view>
			<br>
			<view class="">佐证照片:</view>
			<br>
			<view class="" v-for="(j,index) in i.Imageall" :key="i.Imageall.id" class="img">
				<view class="">扣分理由: {{j.remark}}</view>
				<view class="">{{index+1}}</view>
				<view style="margin: auto;">
					<image :src="j.Image"></image>
				</view>
			</view>
		</view>
		<view v-if="twoiswhich" v-for="(i,index) in allpoint" :key="allpoint.id">
			<view class="">{{i.name}}</view>
			<br>
			<view class="length" v-show="$store.state.score > index ? false:true">仅参考</view>
			<view class="length" v-show="$store.state.score > index ? true:false">扣分值：{{i.Imageall.length}} × {{score}} = {{i.Imageall.length*score>2? (i.Imageall.length*score).toFixed(2) + dist2:(i.Imageall.length*score).toFixed(2)}}</view>
			<br>
			<view>扣分依据：{{i.point}}</view>
			<br>
			<view class="">佐证照片:</view>
			<br>
			<view class="" v-for="(j,index) in i.Imageall" :key="i.Imageall.id" class="img">
				<view class="">扣分理由: {{j.remark}}</view>
				<view class="">{{index+1}}</view>
				<view style="margin: auto;">
					<image :src="j.Image"></image>
				</view>
			</view>
		</view>
		<br>
		<br>
		<br>
		<view class="bottom-btn">
			<button @click="end">结束考评</button>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				allpoint: [],
				allscore:null,
				score:null,
				name:'',
				value:'',
				toscore:[],
				address:'',
				tolsocre:null,
				tolscore:null,
				dist1:'(超出扣分要求,按0.6分算)',
				dist2:'(超出扣分要求,按2分算)',
				oneiswhich:false,
				twoiswhich:false,
				len:[],
				pot:[],
				fixscore:[],
			}
		},
		created() {
			uni.getStorage({
				key: 'alldecifm',
				success: res => {
					console.log('可以了')
					console.log(res)
					this.allpoint = res.data
					console.log(this.allscore)
					console.log(this.$store.state.alltownscore)
					console.log(this.$store.state.alltownscore.length)
					console.log(this.$store.state.value)
					console.log(this.$store.state.allcountrysidescore)
					console.log(this.$store.state.allcountrysidescore.length)
					for(var i=0;i<this.allpoint.length;i++){
						this.len.push(this.allpoint[i].Imageall.length)
						this.pot.push(this.allpoint[i].point)
					}
					console.log(this.len)
					console.log(this.pot)
				}
			})
		},
		onLoad() {
			this.name = this.$store.state.user_name
			this.value = this.$store.state.value
			this.address = this.$store.state.address
			console.log(this.address)
			// uni.getStorage({
			// 	key: 'alldecifm',
			// 	success: res => {
			// 		console.log('可以了')
			// 		console.log(res)
			// 		this.allpoint = res.data
			// 		console.log(this.allscore)
			// 		console.log(this.$store.state.alltownscore)
			// 		console.log(this.$store.state.alltownscore.length)
			// 		console.log(this.$store.state.value)
			// 		console.log(this.$store.state.allcountrysidescore)
			// 		console.log(this.$store.state.allcountrysidescore.length)
			// 		// for(var i=0;i<this.$store.state.decifm;i++){
			// 		// 	this.len.push(this.$store.state.decifm[i].Imageall.length)
			// 		// 	this.pot.push(this.allpoint[i].point)
			// 		// }
			// 		for(var i=0;i<this.allpoint.length;i++){
			// 			this.len.push(this.allpoint[i].Imageall.length)
			// 			this.pot.push(this.allpoint[i].point)
			// 		}
			// 		console.log(this.len)
			// 		console.log(this.pot)
			// 		// console.log(this.len)
			// 		// console.log(this.pot)
			// 	}
			// })
			// for(var i=0;i<this.allpoint.length;i++){
			// 	this.len.push(this.allpoint[i].Imageall.length)
			// 	this.pot.push(this.allpoint[i].point)
			// }
			// console.log(this.len)
			// console.log(this.pot)
			
			// console.log(result);
			if(this.$store.state.value == 'A' || this.$store.state.value == 'B'){
				this.score = 0.12
				this.allscore = 30
				this.oneiswhich = true
			} else if(this.$store.state.value == 'C' || this.$store.state.value == 'D' || this.$store.state.value == 'E'){
				this.score = 0.1
				this.allscore = 30
				this.oneiswhich = true
			} else if(this.$store.state.value == 'a'){
				this.score = 0.4
				this.allscore = 70
				this.twoiswhich = true
			} else if(this.$store.state.value == 'b'){
				this.score = 0.34
				this.allscore = 70
				this.twoiswhich = true
			} else if(this.$store.state.value == 'c'){
				this.score = 0.29
				this.allscore = 70
				this.twoiswhich = true
			}
			if(this.$store.state.value == 'A' || this.$store.state.value == 'C' || this.$store.state.value == 'D' || this.$store.state.value == 'E' || this.$store.state.value == 'B') {
				this.fixscore = this.$store.state.alltownscore
				const data = this.$store.state.alltownscore
				
				const sortedData = [...data].sort((a, b) => a - b);
				const smallestNumbers = sortedData.slice(0, this.$store.state.score);
				
				let count = 0;
				const newData = sortedData.map(item => {
				  if (smallestNumbers.includes(item)) {
				    count++;
				    if (count > this.$store.state.score) {
				      return 0;
				    } else {
				      return item;
				    }
				  } else {
				    return 0;
				  }
				});
				
				console.log('8888888888888888888888888888888888888888',newData);
				this.$store.state.alltownscore = newData
				var sum = 30
				for(var i = 0 ;i<this.$store.state.alltownscore.length;i++){
					sum = sum + this.$store.state.alltownscore[i]
				}
				var tol = 0
				for(var i=0;i<this.$store.state.alltownscore.length-1;i++){
					tol = tol - this.$store.state.alltownscore[i]
				}
				console.log(sum)
				this.allscore = sum
				this.$store.state.alltownscore[50] = sum
				this.allscore = this.allscore.toFixed(2)
				this.tolscore = tol
				this.tolscore = this.tolscore.toFixed(2)
				this.$store.state.alltownscore[50] = this.$store.state.alltownscore[50].toFixed(2)
				this.$store.state.alltownscore[50] = parseFloat(this.$store.state.alltownscore[50])
				console.log(this.$store.state.alltownscore[50])
				this.toscore = this.fixscore
			} else {
				this.fixscore = this.$store.state.allcountrysidescore
				const data = this.$store.state.allcountrysidescore
				
				const sortedData = [...data].sort((a, b) => a - b);
				const smallestNumbers = sortedData.slice(0, this.$store.state.score);
				
				let count = 0;
				const newData = sortedData.map(item => {
				  if (smallestNumbers.includes(item)) {
				    count++;
				    if (count > this.$store.state.score) {
				      return 0;
				    } else {
				      return item;
				    }
				  } else {
				    return 0;
				  }
				});
				
				console.log('8888888888888888888888888888888888888888',newData);
				this.$store.state.allcountrysidescore = newData
				var sum = 70
				for(var i = 0 ;i<this.$store.state.allcountrysidescore.length;i++){
					sum = sum + this.$store.state.allcountrysidescore[i]
				}
				var tol = 0
				for(var i=0;i<this.$store.state.allcountrysidescore.length-1;i++){
					tol = tol - this.$store.state.allcountrysidescore[i]
				}
				console.log(sum)
				this.$store.state.allcountrysidescore[35] = sum
				console.log(this.$store.state.allcountrysidescore[35])
				this.allscore = sum
				this.allscore = this.allscore.toFixed(2)
				this.tolscore = tol
				this.tolscore = this.tolscore.toFixed(2)
				this.$store.state.allcountrysidescore[35] = this.$store.state.allcountrysidescore[35].toFixed(2)
				this.$store.state.allcountrysidescore[35] = parseFloat(this.$store.state.allcountrysidescore[35])
				this.toscore = this.fixscore
			}
			// this.allpoint = this.$store.state.decifm
			console.log(this.allpoint)
		},
		methods:{
			end(){
				uni.showLoading({
					title:'正在保存',
					mask:true
				})
				uni.request({
					url:'http://111.230.59.120:80/kaoping/excel_message/',
					method:'POST',
					data:{
						all_score:this.allscore,
						tol_score:this.tolscore,
						numbers:this.len,
						name:this.name,
						score:this.score,
						category:this.value,
						position:this.address,
						score_list:this.fixscore,
						pot:this.pot
					},
					success:res => {
						console.log(res)
						uni.showToast({
							title:'保存成功,考评完成',
							duration:2500,
							mask:true,
							success:res => {
								console.log(res)
								uni.clearStorage()
								this.$store.state.decifm = []
								// this.$store.state.user_name = '',
								this.$store.state.value = ''
								this.$store.state.alltownscore = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
								this.$store.state.allcountrysidescore = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
								this.$store.state.count = 0
								this.$store.state.load = true
								setTimeout(()=>{
									uni.redirectTo({
										url:'../month'
									})
								},500)
							}
						})
					},
					fail:err =>{
						console.log(err)
						uni.showToast({
							title:'网络超时，请检查网络连接',
							icon:'error'
						})
					}
				})
				
				
			},
			checkimg(e, b) {
				console.log(e)
				console.log(b)
				uni.previewImage({
					urls: [this.allpoint[e.id].Imageall[b].Image],
					success: (res) => {
						console.log(this.Imageforall[e.id].Imageall[b].Image)
					},
					fail: function() {
						uni.showToast({
							title: '网络错误,请检查网络连接',
							icon: 'none'
						});
					}
				})
			},
		},
		onUnload() {
			// uni.clearStorage()
			console.log('清除了soligzts')
		}
	}
</script>

<style scoped>
	.word {
		text-align: center;
		color: yellowgreen;
		font-size: 50rpx;
	}
	table {
		border: 1px solid black;
	}
	.length {
		color: red;
	}
	.all {
		text-align: center;
		font-size: 40rpx;
		/* color: red; */
	}
	.bottom-btn {
		position: fixed;
		margin-top: 20rpx;
		width: 100%;
		bottom: 0rpx;
	}
	
	.bmbtn {
		background-color: skyblue;
		color: whitesmoke;
	}
	.img {
		text-align: center;
	}
</style>